package com.ali.use;

import java.util.Date;
import java.util.HashMap;
import java.util.UUID;

import com.ali.beebot.request.BeeBotRequest;
import com.ali.util.AliETSignUtil;
import com.ali.util.AliYunHttpUtils;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by 煜赜
 * 2018/8/20 9:56
 */
public class UseBeeBot {
    private static final String CHATBOT_URL= "https://chatbot.cn-shanghai.aliyuncs.com/";
    public static void main(String[] args) throws Exception {
        String akId = "LTAINAJm1lPrmcAT";
        String akSecret ="laNsR0DOsXEn2fIljYdmBr0LlosIf9";
        String timeStamp = AliETSignUtil.getSolrDate(new Date());	//请求的时间戳
        String nonce_str = UUID.randomUUID().toString();			//用户在不同请求间要使用不同的随机数值。
        String Utterance = "你好";
        System.out.println("时间："+timeStamp+"\n"+"随机数:"+nonce_str);
        //全部参数
        HashMap<String, Object> hashMap = AliETSignUtil.transBean2Map(new BeeBotRequest("JSON","2017-10-11",akId,""," HMAC-SHA1",timeStamp,"1.0",nonce_str,"Chat", "chatbot-cn-0pp0qmhav000h8", Utterance));
        String sign = AliETSignUtil.getSignature("GET", hashMap, akSecret);
        hashMap.put("Signature", sign);
        String param = AliETSignUtil.getParams(hashMap);
        JSONObject result  = AliYunHttpUtils.sendGet(CHATBOT_URL, param);
        System.out.println(result);
    }
}
